<?php
namespace model;

//  Exempel plockat från: http://us1.php.net/manual/es/function.mcrypt-encrypt.php
class EncryptionModel {
    private $securekey, $iv;
    private $textkey = "olY7rT6901araaA129VN";

    /**
    * __constructor
    */
     function __construct() {
         $this->securekey = hash('sha256',$this->textkey,TRUE);
         $this->iv = mcrypt_create_iv(32);
     }


    /**
    * @param string $input
    * @return string
    *
    * här kodar vi lösenordet så det blir krypterat
    */
     function enCrypt($input) {
        return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv));
     }


    /**
    * @param string $input
    * @return string
    *
    * här avkodar vi lösenordet så det blir i klartext
    */
     function deCrypt($input) {
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv));
     }

}

